<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>团队管理-WMS仓库管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/system.css"/>
    <div class="sp-wrapper">
        <h2 class="sp-title"><span>团队管理</span></h2>
        <form method="get" action="/system/tdgl">
            <div class="sp-tool">
                <span><input type="text" placeholder="姓名" name="name"><input type="text" placeholder="手机号码"
                                                                             name="mobile"><input type="submit"
                                                                                                  value="搜索"><i
                        class="add" id="add" th:attr="d-userid=0">新增员工</i></span>
            </div>
        </form>
        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>登录用户名</th>
                    <th>姓名</th>
                    <th>手机号码</th>
                    <th>所属系统</th>
                    <!--<th>所在分组</th>-->
                    <th>添加时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${lists}">
                    <td th:text="${item.id}">1</td>
                    <td th:text="${item.userName}">张三</td>
                    <td th:text="${item.getTrueName()}">张三</td>
                    <td th:text="${item.getMobile()}">18612348888</td>
                    <td th:text="${item.getSystemId()}">管理员</td>
                    <td >
                        <span th:text="${item.addTime }"></span>
                    </td>
                    <td th:text="${T(com.b2c.entity.enums.UserStateEnums).getName(item.getStatus())}">正常</td>
                    <td>
                        <a th:if="${item.id !=1 }" th:href="@{/system/manage_user_menu(user_id=${item.getId()})}">权限设定</a>
                        <i  th:attr="d-username=${item.getUserName()},d-name=${item.getTrueName()},d-mobile=${item.getMobile()},d-group=${item.getGroupId()},d-status=${item.getStatus()},d-userid=${item.getId()}"
                           class="edit">修改</i>
                        <i th:if="${item.id !=1 }" th:attr="data-id=${item.getId()}" class="delete">删除</i>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="pages">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>
    </div>

    <!-- 模板 新增/修改 -->
    <script type="text/template" id="tpl-group">
        <div class="T-box">
            <form id="sp-form" method="post">
                <input type="hidden" name="userid" id="sp-userid">
                <p><span>用户名</span><input id="sb-username" name="username" type="text"/></p>
                <p><span>姓名</span><input id="sb-name" name="name" type="text"/></p>
                <p><span>手机号</span><input id="sb-phone" name="phone" type="text"/></p>
                <p><span>密码</span><input id="sb-password" name="password" type="text"/></p>
<!--                <p><span>组别</span><select id="sb-group" name="group">
                    <option selected disabled>请选择</option>
                    <option th:each="item :${groupLists}" th:value="${item.getId()}" th:text="${item.getGroupName()}">
                        管理员
                    </option>
                </select></p>-->
                <p><span>状态</span><select id="sb-status" name="status">
                    <option  disabled>请选择</option>
                    <option value="0" selected>正常</option>
                    <option value="1">锁定</option>
                </select></p>
                <p class="text" id="sb-text"></p>
            </form>
        </div>
    </script>

    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">
        $(function () {
            // 新增
            $('#add').click(function () {
                var id = $(this).attr('d-userid');
                Tips.alert({
                    title: '新增员工',
                    content: $('#tpl-group').html(),
                    before: function () {
                        $('#sb-text').text('');
                        if ($('#sb-username').val() == '') {
                            $('#sb-text').text('用户名不能为空');
                            return false;
                        }
                        if ($('#sb-name').val() == '') {
                            $('#sb-text').text('姓名不能为空');
                            return false;
                        }
                        if ($('#sb-phone').val() == '') {
                            $('#sb-text').text('手机号不能为空');
                            return false;
                        }
                        if ($('#sb-status').val() == null) {
                            $('#sb-text').text('请选择状态');
                            return false;
                        }
                        if ($('#sb-password').val() == null) {
                            $('#sb-text').text('密码不能为空');
                            return false;
                        }
                        var data = {
                            userid: id,
                            username: $('#sb-username').val(),
                            name: $('#sb-name').val(),
                            mobile: $('#sb-phone').val(),
                            groupid: '2',
                            status: $('#sb-status').val(),
                            password: $('#sb-password').val()
                        };
                        $.ajax({
                            url: "/ajax_wms_user/execute_manage_user",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('新增成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    $('#sb-text').text(res.msg);
                                }
                            }
                        });
                        return false;
                    }
                });
            });
            // 修改
            $('.edit').click(function () {
                var id = $(this).attr('d-userid');
                var name = $(this).attr('d-name');
                var username = $(this).attr('d-username');
                var mobile = $(this).attr('d-mobile');
                var group = $(this).attr('d-group');
                // alert(group);
                var status = $(this).attr('d-status');
                Tips.alert({
                    title: '修改员工',
                    content: $('#tpl-group').html(),
                    render: function () {
                        $('#yhm').hide();
                        $('#sb-name').val(name);
                        $('#sb-username').val(username);
                        $('#sb-phone').val(mobile);
                        /*$('#sb-password').val(res.password);*/
                        /*$('#sb-group').val(group);*/
                        $('#sb-status').val(status);
                        $('#sp-userid').val(id);
                    },
                    before: function () {
                        var data = {
                            userid: id,
                            username: $('#sb-username').val(),
                            name: $('#sb-name').val(),
                            mobile: $('#sb-phone').val(),
                            groupid: group,
                            status: $('#sb-status').val(),
                            password: $('#sb-password').val()
                        };
                        $.ajax({
                            url: "/ajax_wms_user/execute_manage_user",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('修改成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    location.reload(true);
                                }
                            }
                        });
                        return false;
                    }
                });
            });
            // 删除
            $('.delete').click(function () {
                var data = {
                    userid: $(this).attr('data-id')
                };
                Tips.confirm({
                    title: '删除员工',
                    content: '确认要删除吗？',
                    define: function () {
                        $.ajax({
                            url: "/ajax_wms_user/del_manage_user",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('删除成功', function () {
                                        location.reload(true);
                                    });
                                }
                            }
                        });
                    }
                });
            });
        });
    </script>
    <!-- end sp-wrapper -->

</div>
</body>
</html>
